#! /bin/bash

# awk 'pattern {cmd}', if the cmd misses, it will print the 
# line match the pattern. If the pattern misses, cmd will play
# on every line.

# -F set the field separator.
echo "awk -F: '{print \$1, \$5}' /etc/passwd"
awk -F: '{print $1, $5}' /etc/passwd
echo ""

# -v to set variable of awk, OFS used as output field separator.
echo "awk -F: -v \"OFS=**\" '{print \$1, \$5}' /etc/passwd"
awk -F: -v "OFS=**" '{print $1, $5}' /etc/passwd
echo ""

# we always use awk to do some other things.
# note: there must be ',' between fields, or print won't 
# set field separator between them.
echo "awk -F: '{print \"User\", \$1, \"is really\", \$5}' /etc/passwd"
awk -F: '{print "User", $1, "is really", $5}' /etc/passwd
echo ""

# here we assume that we have a device named "ramdisk" with unknow 
# major number, now we can search from /proc/devices to find out.
# The pattern means the second field equals ramdisk, then print the
# first field, which is exactly the device number.
echo "awk '\$2==\"ramdisk\" {print \$1}' /proc/devices"
awk '$2=="ramdisk" {print $1}' /proc/devices
echo ""

